package com.mind.login;


import com.mind.common.MessageCode;
import com.mind.core.handler.MessageHandler;
import com.mind.core.net.msg.Message;
import com.mind.core.server.DataHelper;
import com.mind.login.model.Player;
import com.mind.login.msg.LoginMessage;
import com.mind.login.msg.SC_TestMsg;
public class LoginHandler implements MessageHandler<Message>{
	public LoginHandler(){}
	
	public void execute(Message message) {
		Player	player=(Player) message.sender();
		switch (message.getMessageType()) {
		case 1001:
			SC_TestMsg testMsg = (SC_TestMsg) message;
			System.out.println(testMsg);
			break;
		case MessageCode.LoginMessage_CODE:
			LoginMessage loginMessage=(LoginMessage)message;
			player.setId(loginMessage.getName());
			DataHelper.getInstance().addOnlinePlayer(player.id(), player);
			break;
//		case MessageCode.CS_LoginMsg_CODE:
//			CS_LoginMsg loginMsg = (CS_LoginMsg) message;
//			String guid = Guid.createGuid(loginMsg.getPlatId(),loginMsg.getNetId());
//			Player _player=	(Player) DataHelper.getInstance().getOnlinePlayer(guid);
//			if(_player!=null){//踢出原有玩家
//				_player.disconnect();
//			}
//			//player.load(loginMsg.getPlatId(),loginMsg.getNetId());
//			DataHelper.getInstance().addOnlinePlayer(guid, player);
//			//player.update();
//			System.out.println("******************************"+player.property.getCharId());
//			break;
//		case MessageCode.ChangeGold_CODE:
//			ChangeGold changeGold=(ChangeGold)message;
//			player.property.setGold(player.property.getGold()+changeGold.getGold());
//			SC_LoginMsg sc_LoginMsg=new SC_LoginMsg(player.id(), player.property.getName(), player.property.getExp(),
//					player.property.getGold());
//			player.sendMessage(sc_LoginMsg);
//			//player.update();
//			System.out.println("******************************"+player.property.getGold());
//			break;
		}
	}
	@Override
	public short[] getTypes() {
		return new short[]{
				MessageCode.LoginMessage_CODE,
				1001};
	}

}
